<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="p" uri="http://paycn.com.cn/pos"%>
	
<div class="header navbar navbar-inverse navbar-fixed-top">
	<div class="navbar-inner">
		<div class="container-fluid">
			<a class="brand" href="<c:url value="/home.html"/>">
				<%-- <img src="<c:url value="/static/image/logo.png"/>" alt="logo"/> --%>
			</a>
			<a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
			<img src="<c:url value="/static/image/menu-toggler.png"/>" alt="" />
			</a>          
			<ul class="nav pull-right">
				<li class="dropdown">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown">
						<i class="icon-tasks"></i>
						<span class="badge" id="wfn-pending-count"></span>
					</a>
					<ul class="dropdown-menu extended">
						<li class="external">
							<a href="<c:url value="/wfn/pending.html"/>">查看所有未处理的工作 <i class="m-icon-swapright"></i></a>
						</li>
					</ul>
				</li>
			
				<li class="dropdown user">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown">
					<img alt="" src="<c:url value="/static/image/avatar1_small.jpg"/>" />
					<span class="username"><p:username/></span>
					<i class="icon-angle-down"></i>
					</a>
					<ul class="dropdown-menu">
						<li><a href="#member-self-password" data-toggle="modal"><i class="icon-lock"></i> 修改密码</a></li>
						<li><a href="<c:url value="/auth/logout.html"/>"><i class="icon-key"></i> 退出</a></li>
					</ul>
				</li>
			</ul>
			
			<div id="member-self-password" class="modal hide fade" tabindex="-1" data-backdrop="static" data-keyboard="false">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"></button>
					<h4>修改密码</h4>
				</div>
				<div class="modal-body">
					<form method="post" id="member-self-password-form" class="form-horizontal">
						<div class="alert alert-error hide">请检查下面的错误</div>
						<div class="control-group">
							<label class="control-label">原密码:</label>
							<div class="controls">
								<input type="password" name="oldPassword" class="m-wrap medium">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">新密码:</label>
							<div class="controls">
								<input type="password" name="newPassword" class="m-wrap medium">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">重输密码:</label>
							<div class="controls">
								<input type="password" name="confirmPassword" class="m-wrap medium">
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn green ensure">确定</button>
					<button type="button" data-dismiss="modal" class="btn">取消</button>
				</div>
			</div>
			<script type="text/javascript" src="<c:url value="/static/js/commons-message.js"/>"></script>
			<script type="text/javascript">
				$(document).ready(function(){
					//workflow 定时获取未处理任务总数
					$("#wfn-pending-count").message("workflow", {frequency:1, url:"<c:url value="/wfn/pendingCount.html"/>"});
				
					function clean_password($form){
						$form.find("input").val("");
						$form.find(".alert").remove();
					}
					
					$("#member-self-password").on("hidden", function(){
						var $form = $("#member-self-password-form");
						$form.find("input").val("");
						$form.find(".alert").remove();
					});
					
					$("#member-self-password .ensure").bind("click", function(){
						var $form = $("#member-self-password-form");
						var op = $form.find("input[name=oldPassword]").val();
						var np = $form.find("input[name=newPassword]").val();
						var cp = $form.find("input[name=confirmPassword]").val();
						$form.find(".alert").remove();
						if(!op){
							$form.prepend("<div class='alert alert-error'> 原密码不能为空</div>");
							return;
						}
						if(!np){
							$form.prepend("<div class='alert alert-error'> 新密码不能为空</div>");
							return;
						}
						if(np!=cp){
							$form.prepend("<div class='alert alert-error'> 两次输入的密码不一致</div>");
							return;
						}
						var url = "<c:url value="/member/password/save.html"/>";
						var datas = $form.serialize();
						$.post(url, datas, function(msg){
							if(msg.status=="success"){
								$form.prepend("<div class='alert alert-success'> "+msg.message+"</div>");
								setTimeout(function(){
									$("#member-self-password").modal("hide");
								}, 800);
							}else{
								$form.prepend("<div class='alert alert-error'> "+msg.message+"</div>");
							}
						}, "json");
					});
				});
			</script>
		</div>
	</div>
</div>
